// 闃叉AJAX閲嶅鎻愪氦閿�
let ajaxLock = false;

// 椤甸潰鍔犺浇瀹屾垚鍚庢墽琛�
$(document).ready(function() {    
    // 鍒濆鍖栨墍鏈夋棩鏈熼€夋嫨鍣�
    $('.J_setdate').each(function() {
        new ruiDatepicker().init('#' + $(this).attr('id'));
    });
    
    // 鏈嶅姟绠€浠嬪唴瀹瑰畾涔�
    const serviceIntros = {
        ai: {
            title: "AI鏅鸿兘璧峰悕 - 铻嶅悎浼犵粺鏅烘収涓庣幇浠ｇ鎶€",
            text: "涓撳璧峰悕骞冲彴鍒╃敤鍏堣繘鐨勪汉宸ユ櫤鑳芥妧鏈紝缁撳悎浼犵粺濮撳悕瀛﹀師鐞嗭紝涓烘偍鎻愪緵鍒涙剰鏃犻檺銆佸瘬鎰忔繁杩滅殑鍚嶅瓧銆傚彧闇€绠€鍗曡緭鍏ユ偍鐨勯渶姹傦紝AI灏嗕负鎮ㄧ敓鎴愬涓嫭鐗硅€屽瘜鏈夋剰涔夌殑鍚嶅瓧閫夋嫨锛屾弧瓒虫偍瀵瑰悕瀛楃殑鎵€鏈夌編濂芥湡鏈涖€�"
        },
        baby: {
            title: "瀹濆疂璧峰悕 - 寮€鍚編濂戒汉鐢熺殑绗竴姝�",
            text: "涓撲笟涓烘柊鐢熷効瀹氬埗鍚夌ゥ鍚嶅瓧锛岀粨鍚堢敓杈板叓瀛椼€佷簲琛屽钩琛°€侀煶褰箟鐞嗙瓑澶氱淮搴﹀垎鏋愶紝涓烘偍鐨勫疂瀹濋€夊彇涓€涓瘬鎰忕編濂姐€佹湕鏈椾笂鍙ｇ殑鍚嶅瓧锛屽姪鍔涘疂瀹濆仴搴锋垚闀匡紝鍓嶇▼浼奸敠銆�"
        },
        bazi: {
            title: "鍏瓧璧峰悕 - 鍛界悊涓庡悕瀛楃殑瀹岀編缁撳悎",
            text: "鏍规嵁鐢熻景鍏瓧鎺ㄧ畻浜旇鍠滃繉锛岀粨鍚堝懡鐞嗘牸灞€锛屼负鎮ㄩ噺韬畾鍒剁鍚堝懡鐞嗛渶姹傜殑鍚嶅瓧銆傚钩琛′簲琛岋紝琛ョ泭鍛藉眬锛屽姪鎮ㄤ簨涓氶『鍒╋紝浜虹敓缇庢弧銆�"
        },
        company: {
            title: "鍏徃璧峰悕 - 浼佷笟鎴愬姛鐨勭涓€姝�",
            text: "涓撲笟浼佷笟鍛藉悕鏈嶅姟锛岀粨鍚堣涓氬睘鎬с€佽€佹澘鍛界悊銆佸競鍦哄畾浣嶇瓑鍥犵礌锛屾墦閫犲ぇ姘斿搷浜€佸埄浜庡搧鐗屼紶鎾殑鍏徃鍚嶇О锛屽姪鍔涗紒涓氳摤鍕冨彂灞曪紝璐㈡簮骞胯繘銆�"
        },
        shop: {
            title: "搴楅摵璧峰悕 - 鐢熸剰鍏撮殕鐨勮捣鐐�",
            text: "涓哄疄浣撳簵鍜岀綉搴楀垱鎰忓懡鍚嶏紝绐佸嚭浜у搧鐗硅壊锛屾槗璁版槗浼犳挱锛屽惛寮曢【瀹㈢溂鐞冿紝鎻愬崌鍝佺墝浠峰€硷紝鍔╂偍鐢熸剰鍏撮殕锛屽浼间簯鏉ャ€�"
        },
        analysis: {
            title: "鍏瓧绮炬壒 - 娲炴倝鍛借繍杞ㄨ抗",
            text: "閫氳繃璇︾粏鍒嗘瀽鎮ㄧ殑鐢熻景鍏瓧锛屽叏闈㈣В璇诲懡鐞嗘牸灞€銆佸ぇ杩愯蛋鍔裤€佷簨涓氳储杩愩€佸濮绘儏鎰熺瓑浜虹敓閲嶈鏂归潰锛屽姪鎮ㄦ妸鎻℃満閬囷紝瓒嬪悏閬垮嚩銆�"
        },
        name: {
            title: "濮撳悕璇︽壒 - 瑙ｇ爜鍚嶅瓧涓殑鍛借繍鐜勬満",
            text: "閫氳繃濮撳悕瀛︿簲鏍煎墫璞℃硶锛岀粨鍚堢敓杈板叓瀛椾笌浜旇鐢熷厠锛屾繁搴﹁В鏋愬鍚嶅浜嬩笟銆佽储杩愩€佸濮荤殑褰卞搷锛屽姪鎮ㄦ礊瀵熷悏鍑讹紝鎶婃彙浜虹敓鏈洪亣銆�"
        },
        caiyun: {
            title: "鍏瓧璐㈣繍 - 娲炶鍛界洏涓殑璐㈠瘜瀵嗙爜",
            text: "娣卞害瑙ｆ瀽鍛藉眬璐㈡槦銆佽储搴撲笌娴佸勾杩愬娍锛岀簿鍑嗛娴嬫璐㈡敹鍏ャ€佸亸璐㈡満閬囧強鎶曡祫椋庨櫓锛屾彁渚涗笓灞炴椇璐㈢瓥鐣ワ紝鍔╂偍鎶婃彙璐㈠瘜榛勯噾鏈熴€�"
        }
    };
    
    // 鍗曢€夋寜閽€夋嫨
    $(document).on('click', '.radio-item', function() {		 
        $(this).find('input[type="radio"]').prop('checked', true);
    });
	
    // 鎵撳紑鍚嶅瓧璇︽儏妯℃€佹
    $(document).on('click', '.J_getinfo', function() {
        var name = $(this).attr('data-name');
        const loadIndex = layer.msg('鑾峰彇濮撳悕[' + name + ']鐨勬祴绠楃粨鏋滀腑...', {
            icon: 16,
            shade: 0.5,
            time: 9999999,
            closeBtn: 2
        });
		
        // 鍙戦€丄JAX璇锋眰		
        $.ajax({
            url: '/?m=api&a=xmfx', 
            type: 'POST',
            dataType: 'json',
            data: {name: name},
            success: function(response) {                               
                if (response.status === 1) {                    
                    const infos = response.data;
                    const nameResults = $('#nameDetails');
                    nameResults.empty(); 
                    
                    // 鍒ゆ柇濮撴皬绗簩涓瓧鏄惁瀛樺湪锛堟牴鎹畝浣撳瓧鍒ゆ柇锛�
                    const hasXsB = infos.xs_b && infos.xs_b.jianti && infos.xs_b.jianti.trim() !== '';
                    // 鍒ゆ柇鍚嶅瓧绗簩涓瓧鏄惁瀛樺湪锛堟牴鎹畝浣撳瓧鍒ゆ柇锛�
                    const hasMzB = infos.mz_b && infos.mz_b.jianti && infos.mz_b.jianti.trim() !== '';
                    
                    const card = `
                        <div class="list-modal-kgs">
                            <h3>鍚嶅瓧璇勪环</h3>
                            <p>鏍规嵁浜旀牸銆佷簲琛屽拰涓夋墠绛夊垎鏋愬緱鍑猴細${infos.name}鐨勫悕瀛楄瘎鍒嗕负锛�<b style="color:#ff6600">${infos.zpfen}</b>鍒嗭紝${infos.pfentxt}</p>
                            <h3>鍩烘湰淇℃伅</h3>
                            <table class="name-table">
                                <thead>
                                    <tr>
                                        <th width="15%">椤圭洰</th>
                                        <th width="20%">濮撴皬(1)</th>
                                        ${hasXsB ? '<th width="20%">濮撴皬(2)</th>' : ''}
                                        <th width="20%">鍚嶅瓧(1)</th>
                                        ${hasMzB ? '<th width="25%">鍚嶅瓧(2)</th>' : ''}
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>绠€浣�</td>
                                        <td><div class="name-character">${infos.xs_a.jianti}</div></td>
                                        ${hasXsB ? `<td><div class="name-character">${infos.xs_b.jianti}</div></td>` : ''}
                                        <td><div class="name-character">${infos.mz_a.jianti}</div></td>
                                        ${hasMzB ? `<td><div class="name-character">${infos.mz_b.jianti}</div></td>` : ''}
                                    </tr>
                                    <tr>
                                        <td>绻佷綋</td>
                                        <td><div class="traditional">${infos.xs_a.fanti}</div></td>
                                        ${hasXsB ? `<td><div class="traditional">${infos.xs_b.fanti}</div></td>` : ''}
                                        <td><div class="traditional">${infos.mz_a.fanti}</div></td>
                                        ${hasMzB ? `<td><div class="traditional">${infos.mz_b.fanti}</div></td>` : ''}
                                    </tr>
                                    <tr>
                                        <td>绗斿垝</td>
                                        <td><div class="strokes">${infos.xs_a.sum}</div></td>
                                        ${hasXsB ? `<td><div class="strokes">${infos.xs_b.sum}</div></td>` : ''}
                                        <td><div class="strokes">${infos.mz_a.sum}</div></td>
                                        ${hasMzB ? `<td><div class="strokes">${infos.mz_b.sum}</div></td>` : ''}
                                    </tr>
                                    <tr>
                                        <td>浜旇</td>
                                        <td><div class="five-elements">${infos.xs_a.wux}</div></td>
                                        ${hasXsB ? `<td><div class="five-elements">${infos.xs_b.wux}</div></td>` : ''}
                                        <td><div class="five-elements">${infos.mz_a.wux}</div></td>
                                        ${hasMzB ? `<td><div class="five-elements">${infos.mz_b.wux}</div></td>` : ''}
                                    </tr>
                                </tbody>
                            </table>
                            
                            <h3>浜旀牸瑙ｆ瀽</h3>
                            <div class="five-grids">
                                <div class="grid-item">
                                    <div class="grid-title">
                                        <i class="fas fa-cloud-sun"></i>
                                        澶╂牸
                                    </div>
                                    <div class="grid-value">${infos.tg}</div>
                                    <div class="grid-number">(${infos.tgm})</div>
                                </div>
                                
                                <div class="grid-item">
                                    <div class="grid-title">
                                        <i class="fas fa-user"></i>
                                        浜烘牸
                                    </div>
                                    <div class="grid-value">${infos.rg}</div>
                                    <div class="grid-number">(${infos.rgm})</div>
                                </div>
                                
                                <div class="grid-item">
                                    <div class="grid-title">
                                        <i class="fas fa-mountain"></i>
                                        鍦版牸
                                    </div>
                                    <div class="grid-value">${infos.dg}</div>
                                    <div class="grid-number">(${infos.dgm})</div>
                                </div>
                                
                                <div class="grid-item">
                                    <div class="grid-title">
                                        <i class="fas fa-globe-asia"></i>
                                        澶栨牸
                                    </div>
                                    <div class="grid-value">${infos.wg}</div>
                                    <div class="grid-number">(${infos.wgm})</div>
                                </div>
                                
                                <div class="grid-item">
                                    <div class="grid-title">
                                        <i class="fas fa-calculator"></i>
                                        鎬绘牸
                                    </div>
                                    <div class="grid-value">${infos.zg}</div>
                                    <div class="grid-number">(${infos.zgm})</div>
                                </div>
                            </div>
                            
                            ${infos.infos}                    
                            
                            ${infos.sancinfo}
                            <div class="moretips">浠ヤ笂娴嬭瘯缁撴灉浠呬緵鍙傝€冿紝鏇磋缁嗗悏鍑跺寲瑙ｄ箣娉曠殑濮撳悕璇︽壒锛屽叓瀛楃簿鎵硅鐐硅繖閲岋細<button class="target-btn" data-tab="name" data-name="${infos.name}">濮撳悕璇︽壒</button></div>
                        </div>
                    `;
                    
                    nameResults.append(card);    
                    setTimeout(function() {
                        layer.close(loadIndex); 
                        $('#nameModal').css('display', 'flex');					
                    }, 2000);
                } else {
                    layer.close(loadIndex); 
                    layer.msg(response.msg, {
                        icon: 2,
                        shade: [0.5, '#000']
                    }, function() {
                        layer.closeAll();
                    });
                }
            },
            error: function() {
                layer.close(loadIndex); 
                layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                    icon: 2,
                    shade: [0.5, '#000']
                }, function() {
                    layer.closeAll();
                });
            }
        });
    });
    
    // 鍏抽棴妯℃€佹    
    $('#closeModal').on('click', function() {
        $('#nameModal').css('display', 'none');
    });
    
    // 鐐瑰嚮妯℃€佹澶栭儴鍏抽棴
    $(window).on('click', function(event) {
        const modal = $('#nameModal');
        if (event.target === modal[0]) {
            closeModal();
        }
    });
	
    // 鍒嗙被瀵艰埅绠＄悊鍣�
    const CategoryManager = {
        $categoriesContainer: $('#nav-scroll-menu'),
        $indicator: $('.floating-indicator'),
        $buttons: $('.nav-menus'),
        $scrollContainer: $('.nav-scroll-container'),
        $container: $('.nav-menu'),
        originalActiveBtn: null,
        isClick: false,

        /** 鍒濆鍖栧鑸鐞嗗櫒 */
        init() {
            this.originalActiveBtn = this.$buttons.filter('.active').first();
            this.initIndicator();
            this.bindEvents();
        },

        /** 鍒濆鍖栨寚绀哄櫒浣嶇疆 */
        initIndicator() {
            if (this.originalActiveBtn.length) {
                this.updateIndicatorPosition(this.originalActiveBtn);
            }
        },

        /** 缁戝畾鎵€鏈変簨浠� */
        bindEvents() {
            // 榧犳爣/瑙︽懜杩涘叆浜嬩欢 - 璋冩暣鎸囩ず鍣�
            this.$buttons.on('mouseenter mousemove touchstart', (e) => {
                this.isClick = e.type === 'touchstart';
                this.$buttons.removeClass('active');
                
                const $btn = $(e.currentTarget);
                const btnWidth = $btn.outerWidth();
                const btnLeft = $btn.position().left;

                // 璁＄畻鎸囩ず鍣ㄦ柊灏哄鍜屼綅缃�
                const newWidth = btnWidth * 1.05;
                const offset = (newWidth - btnWidth) / 2;
                const newLeft = btnLeft - offset;

                this.$indicator.css({
                    width: newWidth,
                    left: newLeft
                });
            });

            // 榧犳爣/瑙︽懜绂诲紑浜嬩欢 - 鎭㈠鍘熸縺娲荤姸鎬�
            this.$buttons.on('mouseleave touchend', (e) => {
                if (!this.isClick && this.originalActiveBtn.length) {
                    this.$buttons.removeClass('active');
                    this.originalActiveBtn.addClass('active');
                    this.updateIndicatorPosition(this.originalActiveBtn);
                }
            });

            // 鐐瑰嚮浜嬩欢 - 鏇存柊婵€娲荤姸鎬�
            this.$buttons.on('click', (e) => {
                this.isClick = true;
                this.originalActiveBtn = $(e.currentTarget);
                
                // 鏇存柊UI
                this.$buttons.removeClass('active');
                this.originalActiveBtn.addClass('active');
                
                // 婊氬姩鍒版寜閽綅缃苟鏇存柊鎸囩ず鍣�
                this.scrollToButton(this.originalActiveBtn);
            });

            // 绐楀彛澶у皬鍙樺寲鏃堕噸鏂拌绠楁寚绀哄櫒浣嶇疆
            let resizeTimer;
            $(window).on('resize', () => {
                clearTimeout(resizeTimer);
                resizeTimer = setTimeout(() => {
                    if (this.originalActiveBtn.length) {
                        this.updateIndicatorPosition(this.originalActiveBtn);
                    }
                }, 200);
            });
        },

        /** 鏇存柊鎸囩ず鍣ㄤ綅缃� */
        updateIndicatorPosition($targetBtn) {
            this.$indicator.css({
                width: $targetBtn.outerWidth(),
                left: $targetBtn.position().left
            });
        },

        /** 婊氬姩鍒版寚瀹氭寜閽綅缃� */
        scrollToButton($targetBtn) {
            const btnOffset = $targetBtn.offset().left;
            const containerOffset = this.$container.offset().left;
            const scrollContainerWidth = this.$scrollContainer.width();
            const btnWidth = $targetBtn.outerWidth();

            // 璁＄畻婊氬姩浣嶇疆锛堢‘淇濇寜閽眳涓樉绀猴級
            let scrollPosition = btnOffset - containerOffset - (scrollContainerWidth - btnWidth) / 2;
            
            // 杈圭晫澶勭悊
            scrollPosition = Math.max(0, Math.min(scrollPosition, this.$container[0].scrollWidth - scrollContainerWidth));

            // 骞虫粦婊氬姩
            this.$scrollContainer.animate({
                scrollLeft: scrollPosition
            }, {
                duration: 300,
                easing: 'swing'
            });
        }
    };

    // 鍒濆鍖栧鑸寚绀哄櫒
    CategoryManager.init();	
	
    // 鍏瓧绮炬壒鎸夐挳
    $(document).on('click', '.target-btn', function() {
        // 鑾峰彇鐩爣閫夐」鍗D		
        $('#nameModal').css('display', 'none');
        const tabId = $(this).data('tab');
        $('a[href="#"][data-tab="' + tabId + '"]').trigger('click');        
        if (tabId == 'name') {
            //const name = $(this).data('name');
            $('#name-xing').focus();
        }        
        CategoryManager.init();
    });
	
    // 瀵艰埅鍒囨崲鍔熻兘
    //$('.nav-menu a').on('click', function(e) {
    //    e.preventDefault();
        
        // 鑾峰彇鐩爣閫夐」鍗D
    //    const tabId = $(this).data('tab');
        
        // 鏇存柊瀵艰埅婵€娲荤姸鎬�
    //    $('.nav-menu a').removeClass('active');
    //    $(this).addClass('active');
        
        // 鏄剧ず瀵瑰簲鍐呭闈㈡澘
    //    $('.tab-pane').removeClass('active');
    //    $(`#${tabId}-tab`).addClass('active');
        
        // 鏇存柊鏈嶅姟绠€浠嬪唴瀹�
    //    if (serviceIntros[tabId]) {
    //        $('#intro-title').text(serviceIntros[tabId].title);
    //        $('#intro-text').text(serviceIntros[tabId].text);
    //    }
    //    $("#publicAddrSelect").hide();
	//	$("#indexPopIndustryShop").removeClass("show");
	//	$("#indexPopIndustry").removeClass("show");
        // 鏇存柊鏈嶅姟鏍囬锛堝悓姝ュ浘鏍囧拰鏂囧瓧锛�
    //    $('.service-header h2').html(`<i class="fas ${$(this).find('i').attr('class').split(' ')[1]}"></i> ${$(this).text().trim()}`);
    //    $('html, body').animate({
    //        scrollTop: $(`#${tabId}-tab`).offset().top - 300  // 鑾峰彇鍏冪礌鐩稿浜庢枃妗ｉ《閮ㄧ殑浣嶇疆
    //    }, 500);  
        
    //});

    // AI璧峰悕琛ㄥ崟鎻愪氦澶勭悊
    $('#ai-btn').click(function() {        
        const formId = $(this).attr('id');
        const tabId = formId.split('-')[0];         
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            surname: $('#ai-surname').val(),      // 濮撴皬
            gender: $('input[name="ai-gender"]:checked').val(),  // 鎬у埆
            birthday: $('#b_input_ai').val(),      // 鏃ユ湡
            birthdate: $('#ai-birthdate').val(),  // 鐢熸棩
            wordCount: $('input[name="ai-word"]:checked').val(), // 瀛楁暟
            hour: $('#b_hour_ai').val(),    // 鏃惰景           
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.surname) {			
            layer.msg('璇疯緭鍏ュ姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {
                $('html, body').animate({
                    scrollTop: $('#ai-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ姘�', '#ai-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#ai-surname').focus();
                    }
                });
            });            
            return false;
        }
        
        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.birthdate) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#ai-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#ai-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        
                    }
                });
            });   
            return false;
        }
        
        // 鏄剧ず鍔犺浇鎻愮ず
        const loadIndex = layer.msg('鐢熻景鍏瓧鍒嗘瀽涓�...', {
            icon: 16,
            shade: 0.5,
            time: 9999999,
            closeBtn: 2
        });
        
        // 鍙戦€丄JAX璇锋眰		
		setTimeout(function() {
        $.ajax({
            url: '/?m=index&a=api', 
            type: 'POST',
            dataType: 'json',
            data: formData,
            success: function(response) {				
                layer.close(loadIndex);                
                if (response.status === 1) {
                    // 澶勭悊杩斿洖鐨勫悕瀛楁暟鎹�
                    const names = response.data;
                    const nameResults = $('.name-results');
                    nameResults.empty();                    
                    
                    if (names && names.length > 0) {                        
                        names.forEach(name => {
                            const card = `
                                <div class="name-card">
                                    <div class="name-card-header">
                                        <div class="name-card-title">${name.fullName}</div>
                                        <div class="name-card-rating">
                                            <i class="fas fa-star"></i> ${name.fen}鍒�
                                        </div>
                                    </div>
                                    <div class="name-card-content">
                                        <div class="name-card-section meaning">
                                            <h4><i class="fas fa-lightbulb"></i> 鍚嶅瓧瀵撴剰</h4>
                                            <p>${name.meaning}</p>
                                        </div>
                                        <div class="name-card-section source">
                                            <h4><i class="fas fa-book-open"></i> 浜旇鍒嗘瀽</h4>
                                            <p>${name.wuxing}</p>
                                        </div>
                                        <div class="name-card-section element">
                                            <h4><i class="fas fa-yin-yang"></i> 鏂囧寲鍑哄</h4>
                                            <p>${name.source}</p>
                                        </div>
                                    </div>
                                </div>
                            `;
                            nameResults.append(card);    
                        });
                        
                        $(`#${tabId}-result`).addClass('active');                        
                        // 婊氬姩鍒扮粨鏋滃尯鍩�
                        $('html, body').animate({
                            scrollTop: $(`#${tabId}-result`).offset().top - 100
                        }, 500);
                    } else {
                        layer.msg('鏈敓鎴愮鍚堣姹傜殑鍚嶅瓧锛岃璋冩暣鏉′欢閲嶈瘯', {
                            icon: 2,
                            shade: [0.5, '#000']
                        }, function() {
                            layer.closeAll();
                        });
                    }
                } else {
                    layer.msg(response.msg, {
                        icon: 2,
                        shade: [0.5, '#000']
                    }, function() {
                        layer.closeAll();
                    });
                }
            },
            error: function() {
                layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                    icon: 2,
                    shade: [0.5, '#000']
                }, function() {
                    layer.closeAll();
                });
            }
        });
		},2000);
    });
    
    // AI璧峰悕琛ㄥ崟鎻愪氦澶勭悊 - 鏁版嵁搴撶増
    $('#ai-btns').click(function() {        
        const formId = $(this).attr('id');
        const tabId = formId.split('-')[0];         
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            xing: $('#ai-surname').val(),      // 濮撴皬
            gender: $('input[name="ai-gender"]:checked').val(),  // 鎬у埆            
            birthday: $('#b_input_ai').val(),  // 鐢熸棩
            hour: $('#b_hour_ai').val(),  // 鏃惰景
            num: $('input[name="ai-word"]:checked').val(), // 瀛楁暟            
        };        
        // 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.xing) {			
            layer.msg('璇疯緭鍏ュ姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {
                $('html, body').animate({
                    scrollTop: $('#ai-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ姘�', '#ai-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#ai-surname').focus();
                    }
                });
            });            
            return false;
        }
        
        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.birthday) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#ai-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#ai-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        
                    }
                });
            });   
            return false;
        }
        
        // 鏄剧ず鍔犺浇鎻愮ず
        const loadIndex = layer.msg('鐢熻景鍏瓧鍒嗘瀽涓�...', {
            icon: 16,
            shade: 0.5,
            time: 9999999,
            closeBtn: 2
        });
        
        // 鍙戦€丄JAX璇锋眰
        setTimeout(function() {
            $.ajax({
                url: '/?m=api&a=index', 
                type: 'POST',
                dataType: 'json',
                data: formData,
                success: function(response) {
                    layer.close(loadIndex);                
                    if (response.status === 1) {
                        // 澶勭悊杩斿洖鐨勫悕瀛楁暟鎹�                    
                        const infos = response.data;
                        const names = infos.list;
                        const wxfx = infos.wxfx.wxgs.arr;
                        const nameResults = $('.name-results');
                        nameResults.addClass('block');
                        nameResults.empty();  
                        var wxcard = "";
                        if (wxfx && wxfx.length > 0) {                        
                            wxfx.forEach(wxs => {
                                 wxcard += `
                                    <div class="element-item element-metal">
                                       <div class="element-title">${wxs[1]}</div>
                                       <div class="element-count">${wxs[0]}</div>
                                    </div>
                                `;                               
                            });
                        }	                        
                        var html = `<div class="list-card">
                            <h2 class="list-card-title"><i class="fas fa-user"></i>涓汉淇℃伅</h2>
                            <div class="list-info-flex">
                              <div class="list-info-item xs">
                                <span class="list-info-label">濮撴皬</span>
                                <span class="list-info-value support-element">${infos.xs}</span>
                              </div>
                              <div class="list-info-item xb">
                                <span class="list-info-label">鎬у埆</span>
                                <span class="list-info-value support-element">${infos.xb}</span>
                              </div>
                              <div class="list-info-item">
                                <span class="list-info-label">鍑虹敓鏃ユ湡</span>
                                <span class="list-info-value missing-element">${infos.nongli}</span>
                              </div>
                              <div class="list-info-item bzl">
                                <span class="list-info-label">鐢熻景鍏瓧</span>
                                <span class="list-info-value bazi-element">${infos.bazi}
                                <button class="target-btn" data-tab="analysis">鍏瓧绮炬壒</button>
                                <div class="finger">
                                <i class="fas fa-hand-point-up"></i>
                                </div>
                                </span>
                              </div>
                            </div>
                          </div>
                          <div class="list-card">
                            <h2 class="list-card-title"><i class="fas fa-scroll"></i>鍏瓧鍛界洏</h2>
                            ${infos.minpan}
                          </div>
                          <div class="list-card">
                            <h2 class="list-card-title"><i class="fas fa-yin-yang"></i>浜旇鍒嗘瀽</h2>
                            <div class="element-analysis">
                              ${wxcard}
                            </div>
                            <p class="bazi-element rel"><strong>浜旇鍒嗘瀽锛�</strong>${infos.wxfx.wxgs.desc} ${infos.wxfx.bfwx}</p>
                            <p class="missing-element que"><strong>浜旇鎵€缂猴細</strong>${infos.wxfx.quewx}</p>
                          </div>`;
                          
                        var card = "";
                        if (names && names.length > 0) {                        
                            names.forEach(name => {
                                 card += `
                                    <div class="list-name-card J_getinfo" data-name="${name.k}">
                                        <div class="list-name-text">${name.k}</div>
                                        <div class="list-name-score">${name.fen}鍒�</div>
                                    </div>
                                `;                               
                            });
                            
                            html += `<div class="names-section">
                                <h2 class="list-card-title"><i class="fas fa-crown"></i>鎺ㄨ崘鍚嶅瓧</h2>
                                <p>鏍规嵁鎮ㄧ殑鐢熻景鍏瓧鍜屼簲琛屾儏鍐碉紝鎴戜滑绮惧績鎸戦€変簡浠ヤ笅鍚嶅瓧锛�(<span class="red">鐐瑰嚮鍚嶅瓧鍙煡鐪嬭瑙�</span>)</p>
                                <div class="names-grid">
                                  ${card}
                                </div>                    
                              </div>
                              `;			
                            nameResults.html(html);
                            $(`#${tabId}-result`).addClass('active');    
                            $('.list-btn').show();
                            // 婊氬姩鍒扮粨鏋滃尯鍩�
                            $('html, body').animate({
                                scrollTop: $(`#${tabId}-result`).offset().top - 100
                            }, 500);
							$('#free').html(response.msg);
                        } else {
                            layer.msg('鏈敓鎴愮鍚堣姹傜殑鍚嶅瓧锛岃璋冩暣鏉′欢閲嶈瘯', {
                                icon: 2,
                                shade: [0.5, '#000']
                            }, function() {
                                layer.closeAll();
                            });
                        }
                    } else {
                        layer.msg(response.msg, {
                            icon: 2,
                            shade: [0.5, '#000']
                        }, function() {
                            layer.closeAll();
                        });
                    }
                },
                error: function() {
                    layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                        icon: 2,
                        shade: [0.5, '#000']
                    }, function() {
                        layer.closeAll();
                    });
                }
            });
        }, 1000);
    });
	
    // 鏇村鍚嶅瓧
    $('.list-btn,#ai-user').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁        
        const sex = $('input[name="ai-gender"]:checked').val();
        var gender = 0;
        if (sex == 'male') {
            gender = 1;
        }
        
        const formData = {
            xing: $('#ai-surname').val(),      // 濮撴皬
            gender: gender,  // 鎬у埆   
            datetext: $('#ai-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_ai').val(),  // 鐢熸棩
            hour: $('#b_hour_ai').val(),  // 鏃惰景
            remarks: '',
            born: 1,
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.xing) {			
            layer.msg('璇疯緭鍏ュ姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#ai-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ姘�', '#ai-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#ai-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#ai-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#ai-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#ai-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }
        
        PostAjax(formData, 'baobaoqm');
    });
    
    // 瀹濆疂璧峰悕琛ㄥ崟鎻愪氦澶勭悊
    $('#baby-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;
        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            xing: $('#baby-surname').val(),               // 濮撴皬
            gender: $('input[name="baby-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#baby-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_baby').val(),           // 鐢熸棩
            hour: $('#b_hour_baby').val(),                // 鏃惰景
            remarks: $('#baby-remarks').val(),            // 澶囨敞
            born: 1,
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.xing) {			
            layer.msg('璇疯緭鍏ュ疂瀹濆姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#baby-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ疂瀹濆姘�', '#baby-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#baby-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨瀹濆疂鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#baby-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨瀹濆疂鍑虹敓鏃ユ湡', '#baby-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#baby-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }
        
        PostAjax(formData, 'baobaoqm');
    });
	// 鍏瓧璧峰悕琛ㄥ崟鎻愪氦澶勭悊
    $('#bazi-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            username: $('#bazi-surname').val(),               // 濮撴皬
			born: $('input[name="bazi-born"]:checked').val(),  // 鍑虹敓鐘舵€�
            gender: $('input[name="bazi-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#bazi-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_bazi').val(),           // 鐢熸棩
            hour: $('#b_hour_bazi').val(),                // 鏃惰景            
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ュ疂瀹濆姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#bazi-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ疂瀹濆姘�', '#bazi-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#bazi-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨瀹濆疂鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#bazi-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨瀹濆疂鍑虹敓鏃ユ湡', '#bazi-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#bazi-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }
        
        PostAjax(formData, 'bzqm');
    });
    
	// 鍏徃璧峰悕琛ㄥ崟鎻愪氦澶勭悊
    $('#company-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            username: $('#company-surname').val(),               // 濮撳悕
			stype: $('input[name="company-stype"]:checked').val(),  // 瀛楁暟
            gender: $('input[name="company-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#company-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_company').val(),           // 鐢熸棩
            hour: $('#b_hour_company').val(),                // 鏃惰景            
			city:$('#company-city').val(),//鍩庡競
			industry_id:$('.J_industryInputId').val(),//琛屼笟
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撳悕
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ユ硶浜哄鍚�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#company-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ユ硶浜哄鍚�', '#company-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#company-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨娉曚汉鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#company-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨娉曚汉鍑虹敓鏃ユ湡', '#company-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#company-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }
        
		// 琛ㄥ崟楠岃瘉 - 鍩庡競
        if (!formData.city) {			
            layer.msg('璇烽€夋嫨鍩庡競', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#company-city').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍩庡競', '#company-city', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#company-city').focus();
                    }
                });
            });            
            return false;
        }
		
		// 琛ㄥ崟楠岃瘉 - 琛屼笟
        if (!formData.industry_id) {			
            layer.msg('璇烽€夋嫨琛屼笟', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#company-industry').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨琛屼笟', '#company-industry', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#company-industry').focus();
                    }
                });
            });            
            return false;
        }
        PostAjax(formData, 'gongsi');
    });
	// 搴楅摵璧峰悕琛ㄥ崟鎻愪氦澶勭悊
    $('#shop-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            username: $('#shop-surname').val(),               // 濮撳悕
			stype: $('input[name="shop-stype"]:checked').val(),  // 瀛楁暟
            gender: $('input[name="shop-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#shop-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_shop').val(),           // 鐢熸棩
            hour: $('#b_hour_shop').val(),                // 鏃惰景            
			city:$('#shop-city').val(),//鍩庡競
			industry_id:$('.J_industryInputIdSshop').val(),//琛屼笟
            privacy_protocol: 'on'
        };
		
		// 琛ㄥ崟楠岃瘉 - 鍩庡競
        if (!formData.city) {			
            layer.msg('璇烽€夋嫨鍩庡競', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#shop-city').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍩庡競', '#shop-city', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#shop-city').focus();
                    }
                });
            });            
            return false;
        }
		
		// 琛ㄥ崟楠岃瘉 - 琛屼笟
        if (!formData.industry_id) {			
            layer.msg('璇烽€夋嫨琛屼笟', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#shop-industry').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨琛屼笟', '#shop-industry', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#shop-industry').focus();
                    }
                });
            });            
            return false;
        }
        
        // 琛ㄥ崟楠岃瘉 - 濮撳悕 
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ュ簵涓诲鍚�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#shop-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ簵涓诲鍚�', '#shop-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#shop-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨搴椾富鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#shop-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨搴椾富鍑虹敓鏃ユ湡', '#shop-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#shop-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }
        
		
        PostAjax(formData, 'dianpuqm');
    });
	
	// 鍏瓧绮炬壒琛ㄥ崟鎻愪氦澶勭悊
    $('#analysis-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            username: $('#analysis-surname').val(),               // 濮撳悕			
            gender: $('input[name="analysis-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#analysis-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_analysis').val(),           // 鐢熸棩
            hour: $('#b_hour_analysis').val(),                // 鏃惰景        
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撳悕
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ュ鍚�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#analysis-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ鍚�', '#analysis-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#analysis-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#analysis-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#analysis-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#analysis-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }       
		
        PostAjax(formData, 'bazijingpi');
    });
	
	// 濮撳悕璇︽壒琛ㄥ崟鎻愪氦澶勭悊
    $('#name-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
			xing: $('#name-xing').val(),//濮撴皬
            username: $('#name-mingzi').val(),               // 鍚嶅瓧			
            gender: $('input[name="name-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#name-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_name').val(),           // 鐢熸棩
            hour: $('#b_hour_name').val(),                // 鏃惰景        
            privacy_protocol: 'on'
        };
        
		// 琛ㄥ崟楠岃瘉 - 濮撴皬
        if (!formData.xing) {			
            layer.msg('璇疯緭鍏ュ姘�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#name-xing').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ姘�', '#name-xing', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#name-xing').focus();
                    }
                });
            });            
            return false;
        }
        // 琛ㄥ崟楠岃瘉 - 鍚嶅瓧
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ュ悕瀛�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#name-mingzi').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ悕瀛�', '#name-mingzi', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#name-mingzi').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#name-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#name-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#name-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }       
		
        PostAjax(formData, 'jieming');
    });
	
	// 鍏瓧璐㈣繍琛ㄥ崟鎻愪氦澶勭悊
    $('#caiyun-btn').click(function() {        
        // 闃叉閲嶅鎻愪氦
        if (ajaxLock) return false;        
        // 鏀堕泦琛ㄥ崟鏁版嵁
        const formData = {
            username: $('#caiyun-surname').val(),               // 濮撳悕			
            gender: $('input[name="caiyun-gender"]:checked').val(),  // 鎬у埆
            datetext: $('#caiyun-birthdate').val(),         // 鏃ユ湡鏂囨湰
            birthday: $('#b_input_caiyun').val(),           // 鐢熸棩
            hour: $('#b_hour_caiyun').val(),                // 鏃惰景        
            privacy_protocol: 'on'
        };
        
        // 琛ㄥ崟楠岃瘉 - 濮撳悕
        if (!formData.username) {			
            layer.msg('璇疯緭鍏ュ鍚�', {
                icon: 0,
                time: 2000, 
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#caiyun-surname').offset().top - 180
                }, 500);
                layer.tips('璇疯緭鍏ュ鍚�', '#caiyun-surname', {
                    tips: [1, '#16b777'],
                    end: function() {
                        $('#caiyun-surname').focus();
                    }
                });
            });            
            return false;
        }

        // 琛ㄥ崟楠岃瘉 - 鍑虹敓鏃ユ湡
        if (!formData.datetext) {
            layer.msg('璇烽€夋嫨鍑虹敓鏃ユ湡', {
                icon: 0,
                time: 2000,
                shade: [0.5, '#000']
            }, function() {    
                $('html, body').animate({
                    scrollTop: $('#caiyun-birthdate').offset().top - 180
                }, 500);
                layer.tips('璇烽€夋嫨鍑虹敓鏃ユ湡', '#caiyun-birthdate', {
                    tips: [1, '#16b777'],
                    end: function() {
                        //$('#caiyun-birthdate').focus().trigger('click');
                    }
                });
            });   
            return false;
        }       
		
        PostAjax(formData, 'bazicy');
    });
    function PostAjax(formData, v) {
        ajaxLock = true;	
        // 鏄剧ず鍔犺浇鎻愮ず
        const loadIndex = layer.msg('绯荤粺鏅鸿兘鍒嗘瀽涓�...', {
            icon: 16,
            shade: 0.5,
            time: 9999999,
            closeBtn: 2
        });
        
        // 鍙戦€丄JAX璇锋眰
        $.ajax({
            url: "https://tg.ffceshi.com/product/" + v + "/submit.html",
            type: 'POST',
            data: formData,
            dataType: "json",
            success: function(response) {
                ajaxLock = false;
                layer.close(loadIndex);                        
                if (response.status > 0) {
                    if (response.url) {
                        const queryStr = "sourcea=[sourcea]&theme=&spread=tui&dhid=9";  
                        const windowurl = `https://tg.ffceshi.com${response.url}&${queryStr}`;
                        window.location.href = windowurl;
                    } else {
                        layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                            icon: 2,
                            shade: [0.5, '#000']
                        }, function() {
                            layer.closeAll();
                        });
                    }
                } else {
                    layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                        icon: 2,
                        shade: [0.5, '#000']
                    }, function() {
                        layer.closeAll();
                    });
                }
            },
            error: function() {                        
                ajaxLock = false;		 
                layer.msg('璇锋眰澶辫触锛岃绋嶅悗鍐嶈瘯', {
                    icon: 2,
                    shade: [0.5, '#000']
                }, function() {
                    layer.closeAll();
                }); 
            }
        });
    }
});    